define(
    [
        'zepto',
        'underscore',
        'backbone',
        'config',
        'etopscroll',
        'view/headView'],
    function ($, _, Backbone, config, etopscroll, headView) {
        //jQuery.support.cors = true;
        //全局公用数据
        window.wData = {
            urlData: App.getParams(),//获取URL传参，config里面的方法
            beginHash: App.getParams("hash"),
            index: {},
            supplementaryInfo:{},
            _insured:{},//二级数据 投保人信息
            _policyHolder:{asInsured:true},//二级数据 被保人信息,默认同投保人
            _beneficiary:{asPolicyHolder:true},//二级数据 受益人信息,默认同被保人
            //用于快捷三期测试
//          cardList:[
//              {
//              'bankName':'中国银行中国银行中国银行',
//              'bindingStatus':'1',
//              'bkAcctTp':'01',
//              'cardBegin':'622588',
//              'cardEnd':'6751',
//              'mobNo':'15111111132',
//              'modifyTime':'20170824101629'
//              },
//              {
//              'bankName':'农业银行农业银行农业银行',
//              'bindingStatus':'1',
//              'bkAcctTp':'01',
//              'cardBegin':'622588',
//              'cardEnd':'6752',
//              'mobNo':'15111111132',
//              'modifyTime':'20170824101629'
//              },
//              {
//              'bankName':'交通银行农业银行农业银行',
//              'bindingStatus':'1',
//              'bkAcctTp':'01',
//              'cardBegin':'622588',
//              'cardEnd':'6753',
//              'mobNo':'15111111132',
//              'modifyTime':'20170824101629'
//              },
//              {
//                  'bankName':'交通银行农业银行农业银行',
//                  'bindingStatus':'1',
//                  'bkAcctTp':'01',
//                  'cardBegin':'622588',
//                  'cardEnd':'6754',
//                  'mobNo':'15111111132',
//                  'modifyTime':'20170824101629'
//                  },
//                  {
//                      'bankName':'交通银行农业银行农业银行',
//                      'bindingStatus':'1',
//                      'bkAcctTp':'01',
//                      'cardBegin':'622588',
//                      'cardEnd':'6755',
//                      'mobNo':'15111111132',
//                      'modifyTime':'20170824101629'
//                      }
//          ]
        };
        var Router = Backbone.Router.extend({
            count: 0,
            //保存各种数据的当前状态
            routes: {
                "": "home"//登录
                ,"home":"home"
                ,"newCard":"newCard"
                ,"success":"success"
                ,"fail":"fail"
                ,"unbind":"unbind"
                ,"wait":"wait"
                ,"pay":"pay"
                ,"toPay":"toPay"
                ,"paySucc":"paySucc"
                ,"wxPaySucc":"wxPaySucc"
                ,"wxPayTest":"wxPayTest"
                ,"payAmount":"payAmount"
                ,"bindCard":"bindCard"
                ,"creaditCard":"creaditCard"
                ,"debitCard":"debitCard"
                ,"verifyCode":"verifyCode"
                ,"bindResult":"bindResult"
                ,"qPay":"qPay"
                ,'qPayCardInfo':'qPayCardInfo'
                ,'qPayResult':'qPayResult'
                ,'aliPayTest':'aliPayTest'
                ,'onlineBankbc':'onlineBankbc'
            },

            home: function (options) {
                this.newBodyView("homeView");
            },
            newCard: function (options) {
                this.newBodyView("newCardView");
            },
            success: function (options) {
                this.newBodyView("successView");
            },
            fail: function (options) {
                this.newBodyView("failView");
            },
            unbind: function (options) {
                this.newBodyView("unbindView");
            },
            wait: function (options) {
                this.newBodyView("waitView");
            },
            pay: function (options) {
                this.newBodyView("client/payView");
            },
            toPay: function (options) {
                this.newBodyView("client/toPayView");
            },
            paySucc: function (options) {
                this.newBodyView("client/successView");
            },
            wxPaySucc: function (options) {
                this.newBodyView("client/wxSuccessView");
            },
            wxPayTest:function(){
                this.newBodyView("client/wxPayTestView");
            },
            payAmount: function(options) {
                this.newBodyView("client/payAmountView")
            },
            bindCard: function() {
                this.newBodyView("tied/bindCardView")
            },
            creaditCard: function() {
                this.newBodyView("tied/creaditCardView")
            },
            debitCard: function() {
                this.newBodyView("tied/debitCardView")
            },
            verifyCode: function() {
                this.newBodyView("tied/verifyCodeView")
            },
            bindResult: function() {
                this.newBodyView("tied/bindResultView")
            },
            qPay: function() {
                this.newBodyView("qpay/qPayView")
            },
            qPayCardInfo: function() {
                this.newBodyView("qpay/qPayCardInfoView")
            },
            qPayResult: function() {
                this.newBodyView("qpay/qPayResultView")
            },
            aliPayTest: function() {
                this.newBodyView("client/aliPayView")
            },
            onlineBankbc: function() {
                this.newBodyView('olpay/olPayView')
            },
            //路由初始化可以做一些事
            initialize: function (options) {
                var that = this;
                that.hasHead = true;// 因为现在只有好车主的，所以先默认是false，如果本地调试可以设为true
                App.IS_NATIVE && (that.hasHead =false );
                this.$bodyInit();
                if (wData.beginHash && wData.beginHash != "index") {
                    location.hash = wData.beginHash;
                } else {
                    location.hash = "login";
                }
            },
            $bodyInit : function () {
                if (this.hasHead != true) {
                    window.$main = $("body");
                    window.$main0 = $("body")[0];
                    $main.addClass("main");
                    var $title = $("title");
                    App.title = function (title) {
                        $title.text(title);
                    }
                } else {
                    this.headView = new headView({router: this});
                    window.$main = $("#main");
                    window.$main0 = $("#main")[0];
                    var $head = $("#head h1"),
                        $title = $("title");
                    App.title = function (title) {
                        $head.text(title);
                        $title.text(title);
                    }
                }
            },
            newBodyView: function (url, options, callback) {
                var that = this;
                if (that.bodyView) {
                    that.bodyView.destroy()
                }

                //这个是require框架的临时引入文件,当前是获取传过来的地址,去拿url这个变量名称的文件
                require(['view/' + url], function (view) {
                    //加载完文件之后,去new 他,就等于new 一个写好的function
                    that.bodyView = that[url] = new view(options);
                    that.hashChange(url);
                    callback && callback();
                });
            },
            hashChange: function (url) {
                this.lastHash = this.currentHash;
                this.currentHash = url.replace("View", "");
                App.title(this.headTitle[this.currentHash]);
            },
            headTitle: {

                "home":"订单支付"
                ,"newCard":"订单支付"
                ,"success":"支付结果"
                ,"fail":"异常"
                ,"unbind":"解绑银行卡"
                ,"wait":"支付结果"
                ,"client/pay":"支付"
                ,"client/toPay":"跳转支付"
                ,"client/wxPayTest":"跳转支付"
                ,"client/success":"支付成功"
                ,"client/wxSuccess":"支付成功"
                ,"client/payAmount":"支付"
                ,"tied/bindCard": "请绑定本人银行卡"
                ,"tied/creaditCard":"请输入银行卡信息"
                ,"tied/debitCard":"请输入银行卡信息"
                ,"tied/verifyCode":"请输入验证码"
                ,"tied/bindResult":"绑卡结果"
                ,"qpay/qPay":"快捷支付"
                ,"qpay/qPayCardInfo":"请输入银行卡信息"
                ,'qpay/qPayResult':'支付结果'
                ,'client/aliPay':'跳转支付'
                ,'olpay/olPay': '订单支付'
            },
            back: function (options) {
                router.bodyView.back(options);
            }
        });
        return Router; //返回一个未实例化的对象
    });